<?php

/**
 * index.php
 *
 * Main file
 *
 * @package Public
 */

// Compatibility
$version = '5.2.3';//restricted by htmlentities()' 4th parameter
if(version_compare(PHP_VERSION, $version, '<')) {
	die('Required PHP version is ' . $version . ', current is ' . PHP_VERSION);
}

// Environment
define('DEVELOPMENT', ('127.0.0.1' == $_SERVER['REMOTE_ADDR']) || ('::1' == $_SERVER['REMOTE_ADDR']));
//define('DEVELOPMENT', TRUE);
define('APPLICATION_LINK','application/');
define("MEM_START",memory_get_usage(true));

// Behavior
if(TRUE) {
	ini_set('display_errors', 'On');
	error_reporting(E_ALL | E_STRICT);//report all errors
}
else {
	ini_set('display_errors', 'Off');
	error_reporting(0);
}

// Timezone
date_default_timezone_set('Europe/Amsterdam');

// Constants
define('PRIV',	(DEVELOPMENT) ? '' : 'private/');
define('ROOT',	dirname(__FILE__) . DIRECTORY_SEPARATOR);
define('APP',	ROOT . '../'.PRIV.''.APPLICATION_LINK);

// Start library
require_once ROOT . '../'.PRIV.'library/Library.php';
new Library();

if(DEVELOPMENT) {
	// Start timer
	$timer = new Timer();
	$timer->start();
}

// Run!
require_once APP . 'Bootstrap.php';
$frontController = new Bootstrap();
echo $frontController->run();

define("MEM_END",memory_get_usage(true));

if(DEVELOPMENT) {
	// Stop timer
	$time = $timer->stop();
//	echo PHP_EOL . PHP_EOL . '<!--' . $time . '-->';

	// Log times
	$parseLog = new Log(new Mvc_Request(), APP . 'logs/parse.txt');
	$parseLog->write($time."\t".memory_get_peak_usage());
}
